import React from 'react';
import { inject, observer } from 'mobx-react';
import {
  WeaTop,
  WeaRightMenu,
  WeaErrorPage,
  WeaTools,
  WeaNewScroll,
  WeaLocaleProvider,
} from 'ecCom';
import DocOfSubDepartmentContent from './docofsubdepartment/DocOfSubDepartmentContent';
import { toJS } from 'mobx';
import { formatter } from '../util';

const getLabel = WeaLocaleProvider.getLabel;
@inject('docOfSubDepartmentStore')

@observer
class DocOfSubDeoartment extends React.Component {
  componentDidMount() {
    const { docOfSubDepartmentStore } = this.props;
    const { getCondition, getSecNum, getDocNum, getMostCategory
      , getReportData } = docOfSubDepartmentStore;
    getCondition();
    getSecNum();
    getDocNum();
    getMostCategory();
    getReportData();
  }
  componentWillReceiveProps() {
  }
  componentWillUnmount() {
  }
  onRightMenuClick() {
    const Arr = [];
    return Arr;
  }
  getRightMenu() {
    const Arr = [
    ];
    return Arr;
  }
  getButtons() {
    const Arr = [];
    return Arr;
  }
  getdropMenuProps=()=>{
    const { docOfSubDepartmentStore } = this.props;
    const {title}=docOfSubDepartmentStore;
    return {
      collectParams: {
        favname: title,
        favouritetype: 2,
        objid: 0,
        importantlevel: 1,
        link: 'wui/index.html#/main/document/docofsubdepartment',
      },
    }
  }
  getcollectParams=()=>{
    const { docOfSubDepartmentStore } = this.props;
    const {title}=docOfSubDepartmentStore;
    return {
      favname: title,
      favouritetype: 2,
      objid: 0,
      importantlevel: 1,
      link: 'wui/index.html#/main/document/docofsubdepartment',
    }
  }
  render() {
    const { docOfSubDepartmentStore } = this.props;
    const { reportData, title, loading, loadingChart
      , loadingSN, loadingDN, loadingMC } = docOfSubDepartmentStore;
    const loadingNow = loading || loadingChart || loadingSN || loadingDN || loadingMC;
    // 图表_初始化数据
    let ydata = [];
    let xdata = [];
    if (toJS(reportData).datas) {
      toJS(reportData).datas.forEach((item) => {
        ydata.push(item.docNum);
        xdata.push(`${formatter(item.subcompanyname)}(${getLabel(33553, '分部')}ID : ${item.subcompanyid})`);
      });
    }
    return (
      <div className="wea-doc-count">
        <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@dc514i`}
          collectParams={this.getcollectParams()}
          datas={this.getRightMenu()}
          onClick={this.onRightMenuClick}
        >
          <WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@l5y3es`}
            title={title}
            loading={loadingNow}
            icon={<i className="icon-coms-doc" />}
            iconBgcolor="#df583a"
            buttons={this.getButtons()}
            buttonSpace={10}
            showDropIcon={true}
            dropMenuDatas={this.getRightMenu()}
            onDropMenuClick={this.onRightMenuClick}
            dropMenuProps={this.getdropMenuProps()}
          >
            <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@71x6d3`} height={'100%'}>
              <DocOfSubDepartmentContent ecId={`${this && this.props && this.props.ecId || ''}_DocOfSubDepartmentContent@nls2sy`} ydata={ydata} xdata={xdata} />
            </WeaNewScroll>
          </WeaTop>
        </WeaRightMenu>
      </div>
    );
  }
}

export default WeaTools.tryCatch(React,
  props => <WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@2dsvmw`} msg={props.error ? props.error : getLabel(385218, '对不起，该页面异常，请联系管理员！')} />,
  { error: '' },
)(DocOfSubDeoartment);

